﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Harkon.AppServer.cOne.Service;
using NUnit.Framework;
using System.Reflection;
using Harkon.AppServer.cOne.Registry;
using ComponentC;
using ComponentA;
using ComponentB;
using Harkon.AppServer.cOne.IntegrationTest;

namespace IntegrationTest2
{

    public class CustomIntegrationTestService : IntegrationTestService
    {
        protected override string GetExecutingAssembly()
        {
            return Assembly.GetExecutingAssembly().Location;
        }
    }

    [TestFixture]
    public class IntegrationTest2 : AbstractIntegrationTest
    {
        //Component C
        ServiceName DoStuffName = new ServiceName("DoStuff", "ComponentC", typeof(IDoStuff).FullName);
        IDoStuff DoStuff { get; set; }
        //Component A
        ServiceName WillUseName = new ServiceName("WillUse", "ComponentA", typeof(IWillUse).FullName);
        IWillUse WillUse { get; set; }
        //Component B
        ServiceName ConsumerName = new ServiceName("Consumer", "ComponentB", typeof(IConsumer).FullName);
        IConsumer Consumer { get; set; }
        ServiceName SomeInterfaceName = new ServiceName("SomeInterface", "ComponentB", typeof(ISomeInterface).FullName);
        ISomeInterface SomeInterface { get; set; }

        [TestFixtureSetUp]
        public void SetUp()
        {
            DoStuff = Registry.GetService(DoStuffName) as IDoStuff;
            WillUse = Registry.GetService(WillUseName) as IWillUse;
            Consumer = Registry.GetService(ConsumerName) as IConsumer;
            SomeInterface = Registry.GetService(SomeInterfaceName) as ISomeInterface;
        }

        [Test]
        public void WireupAndStartupTest()
        {
            Assert.IsNotNull(DoStuff);
            Assert.IsNotNull(WillUse);
            Assert.IsNotNull(Consumer);
            Assert.IsNotNull(SomeInterface);

            Assert.AreEqual(DoStuff.CurrentServiceState, ServiceState.Started);
            Assert.AreEqual(WillUse.CurrentServiceState, ServiceState.Started);
            Assert.AreEqual(Consumer.CurrentServiceState, ServiceState.Started);
            Assert.AreEqual(SomeInterface.CurrentServiceState, ServiceState.Started);
        }

        [Test]
        public void ExecutionTest()
        {
            string result = SomeInterface.DoingDoing("stuff");
            Console.WriteLine(result);
        }
    }
}
